package com.atguigu.day01;

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Example4 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Integer> streamSource = env.fromElements(1, 2, 3, 4);
//        streamSource.keyBy(x -> true).sum(0).setParallelism(2).print();
        streamSource.map(x -> Tuple2.of("key", x)).returns(Types.TUPLE(Types.STRING, Types.INT)).setParallelism(3)
                .keyBy(x -> x.f0)
                .sum(1).setParallelism(4)
                .print().setParallelism(2);
        env.execute();
    }
}
